package kr.member.controller;

import java.util.HashMap;
import java.util.Map;

import kr.member.dao.MemberDao;
import kr.member.domain.MemberCommand;
import kr.parking.dao.ParkingDao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class MemberDeleteController {
	@Autowired
	private MemberDao mDao;
	@Autowired
	private ParkingDao pDao;
	
	@RequestMapping("memberDelete.do")
	public String process(@RequestParam("m_num") int m_num){
		System.out.println("m_num : "+m_num);
		
		//MemberCommand mCommand = mDao.selectMember(m_num);
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("m_num", m_num);
		map.put("keyWord", null);
		map.put("keyField", "all");
		int pCount = pDao.getRowCount(map);
		System.out.println("pCount : "+ pCount);
		
		
		if(pCount > 0 ){//주차장이 있으면 삭제 불가능으로 표시 
			String msg = "The car park is owned by the members.<br>The reason is that the member can not be deleted.";
			return "redirect:/memberlist.do?msg="+msg;
		}else{
			mDao.memberDelete(m_num);
		}
		
		return "redirect:/memberlist.do";
	}
}
